﻿// Web Worker Process
var __tempFilePath = "";
var __fso = new ActiveXObject("Scripting.FileSystemObject");
postMessage = function(param) {
	var jsonText = JSON.stringify(param);
	WriteLine(jsonText);
}

function main() {
	var inputText = WScript.StdIn.ReadLine();
	var paramObject = JSON.parse(inputText);
	
	var args = WScript.Arguments;
	if (args.Count() >= 1) {
		__tempFilePath = args(0);
	}
	onmessage(paramObject);
}

function WriteLine(s) {
	WScript.StdOut.WriteLine(s);
	if (__tempFilePath) {
		var ForAppending = 8;
		var TristateTrue = -1;
		var ts = __fso.OpenTextFile(__tempFilePath, ForAppending, true, TristateTrue);
		ts.WriteLine(s);
		ts.Close();
	}
}

main();
